<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<%@ include file="page_header.jsp" %>
<body style="margin: 0">
<%@ include file="page_menu.jsp" %>
<div>
	<div style="margin-top: 0px; background-color: #73BF00;text-align: right">
		<form id="searchForm" onsubmit="changeEncoding();" style="margin: 0px;">
			<input type="text" value="${t_w_i_n_s}" id="enteredWords"/> 
			<input type="submit" value="search"/>
			<input type="hidden" value="${t_w_i_n_s}" name="t_w_i_n_s" id="searchHidden"/>
		</form>
	</div>
	<div class="result_content"> 耗时：<b>${results.searchTime }</b> ms&nbsp;共搜到<b>${results.totalResults}</b>条结果 &nbsp;共${results.totalPages }页</div>
	<div id="searchResultsDivId" style="width:800px;margin-top: 5px;">
		<c:choose>
			<c:when test="${results eq null}">
				<c:out value="无搜索结果"/>
			</c:when>
			<c:otherwise>
				<c:forEach items="${results.resultDatas}" var="result">
					<div class="result">
						<div>
							<c:if test="${result.type eq 0 }">
								<a href="javascript:void(0)" onclick="downloading('${result.resultTitle}','${result.resultAccessPath}');" ><c:out value="${result.resultTitle}"></c:out></a>
								<c:out value="大小：${result.resultSize}b"></c:out>
							</c:if>
							<c:if test="${result.type eq 1 }">
								<a href="javascript:void(0)" onclick="viewContents({'queryParam':'${result.resultTitle}','queryPath':'${result.resultAccessPath}'});" ><c:out value="${result.resultTitle}"></c:out></a>
							</c:if>
						</div>
						<div class="result_content">
							<c:out value="${result.resultContent}" escapeXml="false"></c:out> 
						</div> 
					</div>
				</c:forEach>
			</c:otherwise>
		</c:choose>
	</div>
	<hr/>
	<div>
		<form id="formForPage" method="get">
			分页:
			<c:if test="${t_w_i_n_p > 1}">
		 		<a href="javascript:void(0)" onclick="splitPage(-1)">上一页</a>
			</c:if> 
			<c:if test="${t_w_i_n_p < results.totalPages}">
		 		<a href="javascript:void(0)" onclick="splitPage(1)">下一页</a>
			</c:if> 
			<input type="hidden" value="${t_w_i_n_s}" name="t_w_i_n_s" id="searchHiddenPage"/>
			<input type="hidden" value="${t_w_i_n_p}" name="t_w_i_n_p" id="pageNumHiddenPage"/>
		</form>
	</div>
	<script type="text/javascript">
		var changeEncoding = function () {
			var tempWord = document.getElementById('enteredWords').value;
			document.getElementById('searchHidden').value = encodeURIComponent(tempWord);
			document.getElementById('searchForm').method='GET';
			document.getElementById('searchForm').submit();
			return true;
		}
		
		var splitPage = function (obj) {
			var nextPage = (document.getElementById('pageNumHiddenPage').value)*1+obj*1;
			var tempWord = document.getElementById('searchHiddenPage').value;
			document.getElementById('searchHiddenPage').value = encodeURIComponent(tempWord);
			document.getElementById('pageNumHiddenPage').value = nextPage;
			document.getElementById('formForPage').method='GET';
			document.getElementById('formForPage').submit();
			return true;
		}
		document.getElementById('enteredWords').focus();
		
		var downloading = function (fileName,fileUrl) {
			var link="../download.go?fileName="+fileName+"&fileUrl="+encodeURIComponent(encodeURIComponent(fileUrl))+""; 
			alert(link);
            window.open(link);  
            return false;
		}
		
		var viewContents = function (obj) {
			alert(obj.queryParam+"~"+obj.queryPath);
			return false;
		}
	</script>
</div>	
</body>
</html>